<template>
	<div>
		
		
		
		
		<el-form ref="form" :model="form" label-width="80px">
		  <el-form-item label="客户姓名">
		    <el-input v-model="form.name"></el-input>
		  </el-form-item>
		   <el-form-item label="性别">
			   
		    <el-select v-model="form.gender" placeholder="请选择性别">
		         <el-option label="男" value="1"></el-option>
		         <el-option label="女" value="2"></el-option>
		       </el-select>
		  </el-form-item>
		  
		  
		  
		  <el-form-item label="入驻时间">
		        <el-date-picker type="datetime" 
				 value-format="yyyy-MM-dd HH:mm:ss"
				 placeholder="选择日期" v-model="form.intime" style="width: 100%;"></el-date-picker>
		    </el-form-item>
			
		  
		  <el-form-item>
		    <el-button type="primary" @click="onSubmit">保存</el-button>
		  </el-form-item>
		</el-form>
		
		
		
		
		
		
	</div>
</template>

<script>
	
	export default {
		name:'UserEdit',
		props:["id"],
		data(){
			return{
				form:{
					name:'',
					gender:'',
					intime:null,
				}
			}
		},
		methods:{
			onSubmit(){
				//校验表单，
				
				// 提交 表单 post
				
				this.http.post('/api/customer/save',(success)=>{
					// alert(success)
					if(success){
						 this.$message({
							message: '保存成功',
							type: 'success'
						});
						this.$emit("update:visible",false); //关闭对话框
						this.$emit("flush"); //发起刷新事件
					}
				},this.form)
				
			},
			//修改的时候初始化页面
			init(){
				if(this.id){ //如果有id则需要查询对应的数据
					this.http.get('/api/customer/getById',(customer)=>{
						// this.form.name = customer.name;
						// this.form.gender = customer.gender;
						// this.form.intime = customer.intime;
						// this.form.id = customer.id;
						
						this.form.name = customer;
					
					},{id:this.id})
				}
			}
		},
		created() {
			this.init()
		}
		
	}
</script>

<style>
</style>
